<template>
    <div class="own">
        <el-table :border="true" :data="laws">
            <el-table-column prop="id" v-if="false"></el-table-column>
            <el-table-column label="案号" prop="caseNo" width="150px"></el-table-column>
            <el-table-column label="收案日期" prop="collectionTime" width="100px"></el-table-column>
            <el-table-column label="委托人" prop="caseWtr"></el-table-column>
            <el-table-column label="对方当事人" prop="caseOppositeParties" width="100px"></el-table-column>
            <el-table-column label="承办律师" prop="caseAttorney" width="200px"></el-table-column>
            <el-table-column label="结案" prop="caseSettleStatus">
                <template slot-scope="scope">
                    {{scope.row.caseSettleStatus == 'Y'?'已结案': '未结案'}}
                </template>
            </el-table-column>
            <el-table-column label="代理费" prop="caseAgencyfee" width="70px"></el-table-column>
            <el-table-column label="已付款" prop="casePaidsal" width="70px"></el-table-column>
            <el-table-column label="未付款" prop="caseUnpaidsal" width="70px"></el-table-column>
            <el-table-column label="已开票" prop="caseInvoiced" width="70px"></el-table-column>
            <el-table-column label="未开票" prop="caseNotinvoiced" width="70px"></el-table-column>
            <el-table-column label="收案审批" prop="caseApproveStatus" width="80px">
                <template slot-scope="scope">
                    {{
                    scope.row.caseApproveStatus == '1'?'审批中':
                    scope.row.caseApproveStatus == '2'?'审批不通过':'审批通过'
                    }}
                </template>
            </el-table-column>
            <el-table-column label="收案审批人" prop="systemApprovalName" width="100px"></el-table-column>
            <el-table-column label="合同" prop="caseContract" width="50px">
                <template slot-scope="scope">
                    {{scope.row.caseContract == '1'?'❌': '✔'}}
                </template>
            </el-table-column>
            <el-table-column label="档案" prop="caseRecord" width="50px">
                <template slot-scope="scope">
                    {{scope.row.caseRecord == '1'?'❌': '✔'}}
                </template>
            </el-table-column>
            <el-table-column label="操作">
                <template slot-scope="scope">
                    <el-dropdown trigger="click" @command="handleCommandClick">
                        <el-button>
                            操作<i class="el-icon-arrow-down el-icon--right"></i>
                        </el-button>
                        <el-dropdown-menu slot="dropdown">
                            <el-dropdown-item v-if="scope.row.caseApproveStatus!='2'" :command="beforeHandlerCommand(scope.row,'cost')">费用减免申请</el-dropdown-item>
                            <el-dropdown-item v-if="scope.row.caseApproveStatus=='3' && scope.row.caseApprovalEndtime==null" :command="beforeHandlerCommand(scope.row,'close')">结案</el-dropdown-item>
                            <el-dropdown-item v-if="scope.row.caseApproveStatus!='2'" :command="beforeHandlerCommand(scope.row,'inout')">添加收款记录</el-dropdown-item>
                            <el-dropdown-item v-if="scope.row.caseApproveStatus=='3'" :command="beforeHandlerCommand(scope.row,'invoice')">申请发票</el-dropdown-item>
                            <el-dropdown-item v-if="scope.row.caseApproveStatus=='3'" :command="beforeHandlerCommand(scope.row,'contract')">
                                {{scope.row.caseContract == 1 ?'合同归档':'取消合同归档'}}
                            </el-dropdown-item>
                            <el-dropdown-item v-if="scope.row.caseApproveStatus=='3'" :command="beforeHandlerCommand(scope.row,'record')">
                                {{scope.row.caseRecord == 1 ?'档案归档':'取消档案归档'}}
                            </el-dropdown-item>
                            <el-dropdown-item v-if="scope.row.caseApproveStatus!='2'" :command="beforeHandlerCommand(scope.row,'share')">
                                {{scope.row.caseShare == 1 ?'共享':'取消共享'}}
                            </el-dropdown-item>
                            <el-dropdown-item v-if="scope.row.caseApproveStatus=='2'" :command="beforeHandlerCommand(scope.row,'replace')">重新立案</el-dropdown-item>
                        </el-dropdown-menu>
                    </el-dropdown>
                </template>
            </el-table-column>
        </el-table>
    </div>
</template>

<script>
    import CaseLawService from '../../../model/gs/CaseLawService.js'
    const caseLawService = CaseLawService.getInstance()

    export default {
        props:['laws'],
        data() {
            return {}
        },
        methods:{
            //处理角标变化的方法
            handleCommandClick(command){
                switch (command.type) {
                    case 'share': this.handleUpdateState(command.law,'caseShare');break;
                    case 'contract': this.handleUpdateState(command.law,'caseContract');break;
                    case 'record': this.handleUpdateState(command.law,'caseRecord');break;
                    case 'cost': this.handleCost(command.law);break;
                    case 'close': this.handleClose(command.law);break;
                    case 'inout': this.handleInout(command.law);break;
                    case 'invoice': this.handleInvoice(command.law);break;
                    case 'replace': this.handleReplace(command.law)
                }
            },
            //重新立案的方法
            handleReplace(law){
                this.$emit('replace',law)
            },
            //申请发票的方法
            handleInvoice(law){
                this.$emit('invoice',law)
            },
            //添加收款记录的方法
            handleInout(law){
                this.$emit('inout',law)
            },
            //结案的方法
            handleClose(law){
                this.$emit('close',law)
            },
            //处理分享/合同/档案点击的方法
            handleUpdateState(law,field){
                //判断当前是哪个状态
                if(law[field] == '1'){
                    law[field] = '2'
                }else{
                    law[field] = '1'
                }
                //调用方法更新
                caseLawService.update(law).then(response => {
                    if(response.data.code === 0){
                        this.$emit('reload')
                    }
                })
            },
            //费用减免的方法
            handleCost(law){
                this.$emit('cost',law)
            },
            //角标触发之前的事件
            beforeHandlerCommand(law,type){
                return {
                    law,type
                }
            }
        }
    }
</script>

<style scoped>
    .own{
        width: 100%;
    }
</style>